<!DOCTYPE html>
<html lang='en'>
<head>
    <meta charset='UTF-8'>
    <meta name='viewport' content='width=device-width, initial-scale=1.0'>
    <title>Document</title>
    <script type='text/javascript' src='js/vue.js'></script>
</head>
<body>
    <div id='app'>
        <a href="#/zhuye">主页</a>
        <a href="#/category">分类</a>
        <a href="#/post">文章</a>
        <a href="#/comment">评论</a>
        <component :is="com"></component>
    </div>
    <script type='text/javascript'>
        const zhuye = {
            template: `<h1>主页页面</h1>`
        }
        const category = {
            template: `<h1>分类页面</h1>`
        }
        const post = {
            template: `<h1>文章页面</h1>`
        }
        const comment = {
            template: `<h1>评论页面</h1>`
        }
        var vm = new Vue({
            el: '#app',
            data: {
                msg: 'Hello Vue',
                com: 'zhuye'
            },
            components: {
                zhuye,
                category,
                post,
                comment
            }
        });
        //window.onhashchange不能写成函数形式，会报错
        window.onhashchange = function() {
            // console.log(location.hash);
            let url = location.hash.slice(2);
            vm.com = url;
        }
    </script>
</body>
</html>